package com.sporadic.desk.controller;

import com.sporadic.desk.pojo.UserInfo;
import com.sporadic.desk.service.UserInfoService;
import dto.UserInfoDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vo.ResponseData;

/**
 * @program: sporadic
 * @description:
 * @author: LHD   QQ:1727865856
 * @create: 2019-10-21 16:00
 **/
@RestController
@CrossOrigin(value = "http://localhost:8080")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    /**
     * 没有经过jwt进行验签
     * @param userInfo
     * @return
     */
    @PostMapping("/login")
    public ResponseData<UserInfoDTO> login(@RequestBody UserInfo userInfo) {
        UserInfoDTO userInfoDTO = userInfoService.queryUserInfo(userInfo.getMsTel(), userInfo.getPassWord());
        return userInfoDTO == null ? new ResponseData<>(null, "账号或密码错误") : new ResponseData<UserInfoDTO>(userInfoDTO);
    }

    @PostMapping("/jwtLogin")
    public String jwtlogin(@RequestBody UserInfoDTO userInfoDTO){
        return userInfoService.queryUser(userInfoDTO.getMsTel(), userInfoDTO.getPassWord());
    }

}
